package com.heart.house.biz.service;

import com.heart.house.biz.mapper.CommentMapper;
import com.heart.house.biz.mapper.HouseMapper;
import com.heart.house.common.model.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Luo Zhen
 * @create 2019-06-28 12:00
 */
@Service
public class CommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Value("${file.prefix}")
    private String imgPrefix;

    @Transactional(rollbackFor = Exception.class)
    public void addComment(Comment comment) {
        commentMapper.insertComment(comment);
    }

    public List<Comment> getHouseComments(Long id) {
        List<Comment> comments = commentMapper.getHouseComments(id);
        comments.forEach(c -> {
            c.setAvatar(imgPrefix + c.getAvatar());
        });
        return comments;
    }

    public List<Comment> getBlogComments(Integer id) {
        List<Comment> comments = commentMapper.getBlogComments(id);
        comments.forEach(c -> {
            c.setAvatar(imgPrefix + c.getAvatar());
        });
        return comments;
    }
}
